<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	 	<script type="text/javascript" src="Public/Admin/uploadify/jquery-1.8.2.min.js"></script>
	 	<script>
	 		$(function(){
	 			$(".add").click(function(){
	 				var glstock=$('#glstock').val();

	 				var glnum=$('#glnum').val();
	 				var gid="<?php echo Q('get.gid')?>";
	 				var obj = $("select option:selected");
	 			
	 				var combo = new Array();
	 				for(var i=0;i<obj.length;i++){
	 					
	 					combo.push(obj[i].value);

	 				}
	 				// console.log(combo);
	 				$.ajax({
	 					type:"post",
	 					url:"<?php echo U('GoodsList/add')?>",
	 					data:{combo: combo,glstock:glstock,glnum:glnum,goods_gid:gid},
	 					dataType:'json',
	 					success:function(phpData){
	 						var data=phpData;
	 						var attr = '';
		 						attr+='<tr>';
		 						attr+='<td>'+data.glid+'</td>';
		 							$.each(data.value, function(k,v) { 
		 								console.log(v);
		 								$.each(v, function(k,v){
										attr += '<td>'+v.gtvalue+'</td>';
										})
									 });
		 						attr+='<td>'+data.glstock+'</td><td>'+data.glnum+'</td>';
		 						attr+='<td><a href="" class="btn btn-sm btn-warning">编辑</a>  <a href="" class="btn btn-sm btn-danger">删除</a></td></tr>';
		 						
		 						$("#attra").before(attr);
	 					}
	 				})

	 				
	 			})
	 		})
	 	</script>
	</head>
	<body>
		<table class="table table-hover" >
			<tr class="active">
			  <th width="30">glid</th>
			  
			  <?php foreach ($data as $v){?>
			  	 <th width="200"><?php echo $v['taname']?></th>
			  <?php }?>
			  <th>库存</th>
              <th>货号</th>
			  <th width="200">操作</th>
			  
			 
			</tr>

			<?php foreach ($listData as $v){?>
			<tr >
			
				<td><?php echo $v['glid']?></td>
				<?php foreach ($v['value'] as $value){?>
				<td><?php echo $value['gtvalue']?></td>
				<?php }?>
				<td><?php echo $v['glstock']?></td>
				<td><?php echo $v['glnum']?></td>
				
            
				<td>
					<a href="<?php echo U('GoodsList/edit',array('glid'=>$v['glid']))?>" class="btn btn-sm btn-warning">编辑</a>
					<a href="javascript: if(confirm('确定删除吗？')) location.href='<?php echo U('GoodsList/del',array('glid'=>$v['glid']))?>'" class="btn btn-sm btn-danger">删除</a>
				</td>
			</tr>
			<?php }?>
			
			<tr id='attra'>	
			 	<td width="100">添加商品</td>
			 		<?php foreach ($data as $v){?>
				 		<td>
				 		<select name="" class="select" id="id" gid="<?php echo $v['goods_gid']?>">
			 				<option value="">请选择</option>
			 				<?php foreach ($v['value'] as $value){?>
			 					
			 			   		<option id="id" value="<?php echo $value['gtid']?>" ><?php echo $value['gtvalue']?></option>
			 					
			 				<?php }?>
			 			</select>

			 		</td>
			 		<?php }?>
			 	<td>
            		<input type="text" name="glstock" id="glstock" >
		        </td>
		        <td>
		            <input type="text" name="glnum" id="glnum">
		        </td>
				<td>
					<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large add" />
				</td>
			</tr>
		</table>

	</body>
</html>
